package com.hntxk.cqzd.export.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.alibaba.fastjson.JSON;
import com.hntxk.core.framework.model.ResponseModel;
import com.hntxk.cqzd.common.action.CqzdBaseController;
import com.hntxk.cqzd.export.model.*;
import com.hntxk.cqzd.export.service.PatientInfoService;
import com.hntxk.cqzd.export.service.impl.PatientInfoServiceImpl;
import com.hntxk.cqzd.export.util.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author liucz
 * @version 1.0.0
 * @ClassName PatientInfoController.java
 * @Description TODO
 * @createTime 2021-01-14- 09:31:00
 */
@Api(value="患者信息查询/导出", tags={"[SP]患者信息查询/导出"})
@Controller
@RequestMapping("cqzd/patientInfo")
@Slf4j
public class PatientInfoController extends CqzdBaseController {

    private final PatientInfoService service;

    private final static String LIST_BASE_INFO= "cqzd/history/base_info_index";
    private final static String LIST_CMV_INDEX = "cqzd/history/cmv_index";
    private final static String FOLLOW_UP_INFO_INDEX = "cqzd/history/follow_up_info_index";
    private final static String PUNCTRUE_INDEX = "cqzd/history/punctrue_index";

    @Autowired
    public PatientInfoController(@Qualifier("patientInfo")PatientInfoService service) {
        super(service, LogManager.getLogger(PatientInfoController.class));
        this.service = service;
    }

    @GetMapping(value = "/base")
    public String base() {


        return LIST_BASE_INFO;
    }

    @GetMapping(value = "/cmv")
    public String cmv() {


        return LIST_CMV_INDEX;
    }

    @GetMapping(value = "/follow")
    public String follow() {


        return FOLLOW_UP_INFO_INDEX;
    }

    @GetMapping(value = "/punctrue")
    public String punctrue() {


        return PUNCTRUE_INDEX;
    }

    @ApiOperation("查询CMV")
    @ResponseBody
    @RequestMapping(value = "/getCmv", method = RequestMethod.GET, produces= PRODUCE_UTF8_JSON)
    public ResponseModel getCmv(@ModelAttribute CmvParam model){

        model.setPagination(request);
        //返回查询结果
        if (model.getMark() == 1){
            ResponseModel responseModel = service.query2Json(PatientInfoServiceImpl.MAPPER_NAMESPACE + "getCmv", model, false);
            List<CmvResult>  list = (List<CmvResult>) responseModel.getData();
            List<CmvResult> listResult = service.handleInfo(list);
            responseModel.setData(listResult);
            return responseModel;
        }else {
            return ResponseModel.of(service.getCmv(model));
        }


    }

//    @ApiOperation("导出CMV")
//    @ResponseBody
//    @RequestMapping(value = "/getCmvExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
//    public String getCmvExport(@ModelAttribute CmvParam model, HttpServletResponse response){
//
//        //导出
//        List<CmvResult> cmv = service.getCmv(model);
//        Date currentTime = new Date();
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        cmv.forEach(p -> {
//                    if (null != p.getInspectionTime()) {
//                        p.setStrInspectionTime(formatter.format(p.getInspectionTime()));
//                    }
//                }
//        );
//        ExcelUtil.generateExcelSaveLocal(cmv,
//                ExcelExportConstant.CMV_TITLE,
//                ExcelExportConstant.CMV_FIELD,
//                response,formatter.format(currentTime).replace(":","-"));
//        return JSON.toJSONString("success");
//
//    }
        @ApiOperation("导出CMV")
        @ResponseBody
        @RequestMapping(value = "/getCmvExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
        public ResponseEntity<Object> getCmvExport(@ModelAttribute CmvParam model,HttpServletResponse response) throws IOException {
            //导出
            List<CmvResult> cmv = service.getCmv(model);
            Date currentTime = new Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            cmv.forEach(p -> {
                        if (null != p.getInspectionTime()) {
                            p.setStrInspectionTime(formatter.format(p.getInspectionTime()));
                        }
                    }
            );
            TemplateExportParams params = new TemplateExportParams( "doc/患者CMV信息模板.xls");
            Map<String, Object> map = new HashMap<>(10);
            String fileName = formatter.format(currentTime).replace(":","-")+".xlsx";
            List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
            for (CmvResult tmodel : cmv) {
                Map<String, String> lm = new HashMap<String, String>();
                lm.put("recordId",tmodel.getRecordId());
                lm.put("patientName",tmodel.getPatientName());
                lm.put("patientCardId",tmodel.getPatientCardId());
                lm.put("inspectionItem",tmodel.getInspectionItem());
                lm.put("strInspectionTime",tmodel.getStrInspectionTime());
                lm.put("inspectionProcess",tmodel.getInspectionProcess());
                lm.put("bSign",tmodel.getBSign());
                lm.put("karyoType",tmodel.getKaryoType());
                lm.put("fish",tmodel.getFish());
                lm.put("cnv",tmodel.getCnv());
                lm.put("qfPcr",tmodel.getQfPcr());
                lm.put("other",tmodel.getOther());
                lm.put("diacrisisRemark",tmodel.getDiacrisisRemark());
                listMap.add(lm);
            }
            map.put("maplist", listMap);
            Workbook workbook = ExcelExportUtil.exportExcel(params, map);
            response.setContentType("application/x-download");
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            workbook.write(out);
            byte[] bytes = out.toByteArray();
            return this.toResponseEntity(true, "患者CMV信息 "+fileName, "application/x-download", bytes);


        }


    @ApiOperation("查询患者穿刺信息")
    @ResponseBody
    @RequestMapping(value = "/getPuncture", method = RequestMethod.GET, produces= PRODUCE_UTF8_JSON)
    public ResponseModel getPuncture(@ModelAttribute CmvParam model){
        model.setPagination(request);
        return service.query2Json(PatientInfoServiceImpl.MAPPER_NAMESPACE + "getPuncture", model, false);


    }

//    @ApiOperation("导出患者穿刺信息")
//    @ResponseBody
//    @RequestMapping(value = "/getPunctureExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
//    public String getPunctureExport(@ModelAttribute CmvParam model, HttpServletResponse response){
//        List<PunctureResult> puncture = service.getPuncture(model);
//        Date currentTime = new Date();
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        puncture.forEach(p -> {
//                    if (null != p.getInspectionTime()) {
//                        p.setStrInspectionTime(formatter.format(p.getInspectionTime()));
//                    }
//                }
//        );
//        ExcelUtil.generateExcelSaveLocal(puncture,
//                ExcelExportConstant.PUNCTURE_TITLE,
//                ExcelExportConstant.PUNCTURE_FIELD,
//                response,formatter.format(currentTime).replace(":","-"));
//        return JSON.toJSONString("success");
//
//    }
        @ApiOperation("导出患者穿刺信息")
        @ResponseBody
        @RequestMapping(value = "/getPunctureExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
        public ResponseEntity<Object> getPunctureExport(@ModelAttribute CmvParam model,  HttpServletResponse response) throws IOException {
            model.setMark(2);
            List<PunctureResult> puncture = service.getPuncture(model);
            Date currentTime = new Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            puncture.forEach(p -> {
                        if (null != p.getInspectionTime()) {
                            p.setStrInspectionTime(formatter.format(p.getInspectionTime()));
                        }
                    }
            );
            TemplateExportParams params = new TemplateExportParams( "doc/患者穿刺信息模板.xls");
            Map<String, Object> map = new HashMap<>(10);
            String fileName = formatter.format(currentTime).replace(":","-")+".xlsx";
            List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
            for (PunctureResult tmodel : puncture) {
                Map<String, String> lm = new HashMap<String, String>();
                lm.put("recordId",tmodel.getRecordId());
                lm.put("patientName",tmodel.getPatientName());
                lm.put("patientCardId",tmodel.getPatientCardId());
                lm.put("patientAge",tmodel.getPatientAge()==null ? "" : tmodel.getPatientAge().toString());
                lm.put("assayRemark",tmodel.getAssayRemark());
                lm.put("inspectionItem",tmodel.getInspectionItem());
                lm.put("strInspectionTime",tmodel.getStrInspectionTime());
                listMap.add(lm);
            }
            map.put("maplist", listMap);
            Workbook workbook = ExcelExportUtil.exportExcel(params, map);
            response.setContentType("application/x-download");
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            workbook.write(out);
            byte[] bytes = out.toByteArray();
            return this.toResponseEntity(true, "患者穿刺信息 "+fileName, "application/x-download", bytes);
        }



    @ApiOperation("查询患者基本信息标题")
    @ResponseBody
    @RequestMapping(value = "/getBaseInfo", method = RequestMethod.GET, produces= PRODUCE_UTF8_JSON)
    public ResponseModel getBaseInfo(@ModelAttribute CmvParam model){
        model.setPagination(request);
        return service.query2Json(PatientInfoServiceImpl.MAPPER_NAMESPACE + "getBaseInfo", model, false);

    }


//    @ApiOperation("导出患者基本信息标题")
//    @ResponseBody
//    @RequestMapping(value = "/getBaseInfoExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
//    public String getBaseInfoExport(@ModelAttribute CmvParam model, HttpServletResponse response){
//
//        List<BaseInfoResult> baseInfo = service.getBaseInfo(model);
//        Date currentTime = new Date();
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        baseInfo.forEach(p ->{
//                    if (null != p.getPatientBirthday()) {
//                        p.setStrPatientBirthday(formatter.format(p.getPatientBirthday()));
//                    }
//                    if (null != p.getCreateTime()) {
//                        p.setStrCreateTime(formatter.format(p.getCreateTime()));
//                    }
//                }
//        );
//        ExcelUtil.generateExcelSaveLocal(baseInfo,
//                ExcelExportConstant.BASE_INFO_TITLE,
//                ExcelExportConstant.BASE_INFO_FIELD,
//                response,formatter.format(currentTime).replace(":","-"));
//        return JSON.toJSONString("success");
//
//
//    }
        @ApiOperation("导出患者基本信息标题")
        @ResponseBody
        @RequestMapping(value = "/getBaseInfoExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
        public ResponseEntity<Object> getBaseInfoExport(@ModelAttribute CmvParam model, HttpServletResponse response) throws IOException {
            model.setMark(2);
            List<BaseInfoResult> baseInfo = service.getBaseInfo(model);
            Date currentTime = new Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            baseInfo.forEach(p ->{
                        if (null != p.getPatientBirthday()) {
                            p.setStrPatientBirthday(formatter.format(p.getPatientBirthday()));
                        }
                        if (null != p.getCreateTime()) {
                            p.setStrCreateTime(formatter.format(p.getCreateTime()));
                        }
                    }
            );
            TemplateExportParams params = new TemplateExportParams( "doc/患者基本信息模板.xls");
            Map<String, Object> map = new HashMap<>(16);
            String fileName = formatter.format(currentTime).replace(":","-")+".xlsx";
            List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
            for (BaseInfoResult tmodel : baseInfo) {
                Map<String, String> lm = new HashMap<String, String>();
                lm.put("recordId",tmodel.getRecordId());
                lm.put("patientName",tmodel.getPatientName());
                lm.put("patientCardId",tmodel.getPatientCardId());
                lm.put("sex",tmodel.getSex());
                lm.put("strPatientBirthday",tmodel.getStrPatientBirthday());
                lm.put("patientRace",tmodel.getPatientRace());
                lm.put("patientReligion",tmodel.getPatientReligion());
                lm.put("patientAddress",tmodel.getPatientAddress());
                lm.put("patientAge",tmodel.getPatientAge()== null ? "" : tmodel.getPatientAge().toString());
                lm.put("patientOccupation",tmodel.getPatientOccupation());
                lm.put("patientEdu",tmodel.getPatientEdu());
                lm.put("patientTel",tmodel.getPatientTel());
                lm.put("spouseAge",tmodel.getSpouseAge() == null ? "" : tmodel.getSpouseAge().toString());
                lm.put("spouseOccupation",tmodel.getSpouseOccupation());
                lm.put("spouseEdu",tmodel.getSpouseEdu());
                lm.put("spouseTel",tmodel.getSpouseTel());
                lm.put("strCreateTime",tmodel.getStrCreateTime());
                listMap.add(lm);
            }
            map.put("maplist", listMap);
            Workbook workbook = ExcelExportUtil.exportExcel(params, map);
            response.setContentType("application/x-download");
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            workbook.write(out);
            byte[] bytes = out.toByteArray();
            return this.toResponseEntity(true, "患者基本信息 "+fileName, "application/x-download", bytes);
        }


    @ApiOperation("查询患者随访信息")
    @ResponseBody
    @RequestMapping(value = "/getFollowUpInfo", method = RequestMethod.GET, produces= PRODUCE_UTF8_JSON)
    public ResponseModel getFollowUpInfo(@ModelAttribute CmvParam model){
        model.setPagination(request);
        return service.query2Json(PatientInfoServiceImpl.MAPPER_NAMESPACE + "getFollowUpInfo", model, false);

    }

//    @ApiOperation("导出患者随访信息")
//    @ResponseBody
//    @RequestMapping(value = "/getFollowUpInfoExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
//    public String getFollowUpInfoExport(@ModelAttribute CmvParam model, HttpServletResponse response){
//
//        List<FollowUpInfoResult> followUpInfo = service.getFollowUpInfo(model);
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        followUpInfo.forEach(p ->{
//            if (null != p.getFulpTime()) {
//                p.setStrFulpTime(formatter.format(p.getFulpTime()));
//            }
//            if (null != p.getNbcBirthday()) {
//                p.setStrNbcBirthday(formatter.format(p.getNbcBirthday()));
//            }
//            if (null != p.getChildbirthDate()) {
//                p.setStrChildbirthDate(formatter.format(p.getChildbirthDate()));
//            }
//
//        } );
//        Date currentTime = new Date();
//        ExcelUtil.generateExcelSaveLocal(followUpInfo,
//                ExcelExportConstant.FOLLOW_UP_INFO_TITLE,
//                ExcelExportConstant.FOLLOW_UP_INFO_FIELD,
//                response,formatter.format(currentTime).replace(":","-"));
//        return JSON.toJSONString("success");
//    }
        @ApiOperation("导出患者随访信息")
        @ResponseBody
        @RequestMapping(value = "/getFollowUpInfoExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
        public ResponseEntity<Object> getFollowUpInfoExport(@ModelAttribute CmvParam model, HttpServletResponse response) throws IOException {
            List<FollowUpInfoResult> followUpInfo = service.getFollowUpInfo(model);
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd");
            followUpInfo.forEach(p ->{
                if (null != p.getFulpTime()) {
                    p.setStrFulpTime(formatter.format(p.getFulpTime()));
                }
                if (null != p.getNbcBirthday()) {
                    p.setStrNbcBirthday(formatter2.format(p.getNbcBirthday()));
                }
                if (null != p.getChildbirthDate()) {
                    p.setStrChildbirthDate(formatter2.format(p.getChildbirthDate()));
                }

            } );
            Date currentTime = new Date();
            TemplateExportParams params = new TemplateExportParams( "doc/医护随访信息模板.xls");
            Map<String, Object> map = new HashMap<>(16);
            String fileName = formatter.format(currentTime).replace(":","-")+".xlsx";
            List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
            for (FollowUpInfoResult tmodel : followUpInfo) {
                Map<String, String> lm = new HashMap<String, String>();
                lm.put("recordId",tmodel.getRecordId());
                lm.put("patientName",tmodel.getPatientName());
                lm.put("patientCardId",tmodel.getPatientCardId());
                lm.put("strFulpTime",tmodel.getStrFulpTime());
                lm.put("gestResultName",tmodel.getGestResultName());
                lm.put("sex",tmodel.getSex());
                lm.put("strNbcBirthday",tmodel.getStrNbcBirthday());
                lm.put("nbcBw",tmodel.getNbcBw());
                lm.put("gestAge",tmodel.getGestAge());
                lm.put("birthPlace",tmodel.getBirthPlace());
                lm.put("birthInspection",tmodel.getBirthInspection());
                lm.put("flupCure",tmodel.getFlupCure());
                lm.put("inducedAge",tmodel.getInducedAge());
                lm.put("inducedSpecial",tmodel.getInducedSpecial());
                lm.put("inducedCauseName",tmodel.getInducedCauseName());
                lm.put("isSpecKeep",tmodel.getIsSpecKeep());
                lm.put("specKeepName",tmodel.getSpecKeepName());
                lm.put("isPme",tmodel.getIsPme());
                lm.put("flupRemark",tmodel.getFlupRemark());
                lm.put("strChildbirthDate",tmodel.getStrChildbirthDate());
                lm.put("nbcLength",tmodel.getNbcLength() == null ? "" : tmodel.getNbcLength().toString());
                lm.put("nbcHeadCircumference",tmodel.getNbcHeadCircumference() == null ? "" : tmodel.getNbcHeadCircumference().toString());
                lm.put("oneApgar",tmodel.getOneApgar() == null ? "" : tmodel.getOneApgar().toString());
                lm.put("fiveApgar",tmodel.getFiveApgar() == null ? "" : tmodel.getFiveApgar().toString());
                listMap.add(lm);
            }
            map.put("maplist", listMap);
            Workbook workbook = ExcelExportUtil.exportExcel(params, map);
            response.setContentType("application/x-download");
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            workbook.write(out);
            byte[] bytes = out.toByteArray();
            return this.toResponseEntity(true, "医护随访信息 "+fileName, "application/x-download", bytes);

        }
    @ApiOperation("查询整合患者基础信息、羊穿、绒穿、脐穿、随访患者信息")
    @ResponseBody
    @RequestMapping(value = "/getAllDiagnosisInfo", method = RequestMethod.POST, produces= PRODUCE_UTF8_JSON)
    public ResponseModel getAllDiagnosisInfo(@ModelAttribute AllDiagnosisInfoPar model){
        model.setState(1);
        model.setPagination(request);
        return service.getAllDiagnosisInfo(model);
    }
    @ApiOperation("导出患者基础信息、羊穿、绒穿、脐穿、随访患者信息")
    @ResponseBody
    @RequestMapping(value = "/getAllDiagnosisInfoExport", method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    public ResponseEntity<Object> getAllDiagnosisInfoExport(@ModelAttribute  AllDiagnosisInfoPar model,HttpServletResponse response) throws IOException {
        model.setState(2);
        //导出
        ResponseModel allDiagnosisInfo = service.getAllDiagnosisInfo(model);
        List<AllDiagnosisInfo> data = (List<AllDiagnosisInfo>)allDiagnosisInfo.getData();
        for (int i=0;i<data.size();i++){
            data.get(i).setNumber(i+1);
        }
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        data.forEach(p -> {
                    if (null != p.getLastMenses()) {
                        p.setStrLastMenses(formatter.format(p.getLastMenses()));
                    }
                    if (null != p.getExpectedDate()) {
                        p.setStrExpectedDate(formatter.format(p.getExpectedDate()));
                    }
                    if (null != p.getInspectionTime()) {
                        p.setStrInspectionTime(formatter.format(p.getInspectionTime()));
                    }
                    if (null != p.getFlupTime()) {
                        p.setStrFlupTime(formatter2.format(p.getFlupTime()));
                    }
                    if (null != p.getNbcBirthdayOrChildbirthDate()) {
                        p.setStrNbcBirthdayOrChildbirthDate(formatter.format(p.getNbcBirthdayOrChildbirthDate()));
                    }
                }
        );
        TemplateExportParams params = new TemplateExportParams( "doc/产前诊断患者信息汇总表(基础信息、穿刺信息、随访信息)最新.xlsx");
        Map<String, Object> map = new HashMap<>(16);
        String fileName = formatter2.format(currentTime).replace(":","-")+".xlsx";
        List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
        for (AllDiagnosisInfo tmodel : data) {
            Map<String, String> lm = new HashMap<String, String>();
            lm.put("number",tmodel.getNumber() == null ? "" : tmodel.getNumber().toString());
            lm.put("recordId",tmodel.getRecordId());
            lm.put("patientName",tmodel.getPatientName());
            lm.put("patientCardId",tmodel.getPatientCardId());
            lm.put("patientAge",tmodel.getPatientAge() == null ? "" : tmodel.getPatientAge().toString());
            lm.put("patientEdu",tmodel.getPatientEdu());
            lm.put("patientOccupation",tmodel.getPatientOccupation());
            lm.put("patientReligion",tmodel.getPatientReligion());
            lm.put("gestCount", tmodel.getGestCount() == null ? "" : tmodel.getGestCount().toString());
            lm.put("prodCount", tmodel.getProdCount() == null ? "" : tmodel.getProdCount().toString());
            lm.put("aboCount", tmodel.getAboCount() == null ? "" : tmodel.getAboCount().toString());
            lm.put("badGest",tmodel.getBadGest());
            lm.put("children", tmodel.getChildren() == null ? "" : tmodel.getChildren().toString());
            lm.put("strLastMenses",tmodel.getStrLastMenses());
            lm.put("fetusesType",tmodel.getFetusesType());
            lm.put("gestWeeks", tmodel.getGestWeeks() == null ? "" : tmodel.getGestWeeks().toString());
            lm.put("strExpectedDate",tmodel.getStrExpectedDate());
            lm.put("drugUse",tmodel.getDrugUse());
            lm.put("familyMedical",tmodel.getFamilyMedical());
            lm.put("specialMedical",tmodel.getSpecialMedical());
            lm.put("assayRemark",tmodel.getAssayRemark());
            lm.put("strInspectionTime",tmodel.getStrInspectionTime());
            lm.put("nt", tmodel.getNt() == null ? "" : tmodel.getNt().toString());
            lm.put("crl", tmodel.getCrl() == null ? "" : tmodel.getCrl().toString());
            lm.put("niptTypeName",tmodel.getNiptTypeName());
            lm.put("tangScreenName",tmodel.getTangScreenName());
            lm.put("babnormal","null".equals(tmodel.getBabnormal()) ? "" :tmodel.getBabnormal());
            lm.put("bloodTypeName",tmodel.getBloodTypeName());
            lm.put("patientAddress",tmodel.getPatientAddress());
            lm.put("patientTel",tmodel.getPatientTel());
            lm.put("spouseTel",tmodel.getSpouseTel());
            lm.put("spouseAge", tmodel.getSpouseAge() == null ? "" : tmodel.getSpouseAge().toString());
            lm.put("spouseName",tmodel.getSpouseName());
            lm.put("spouseOccupation",tmodel.getSpouseOccupation());
            lm.put("bsignYc",tmodel.getBsignYc());
            lm.put("afTypeNameYc",tmodel.getAfTypeNameYc());
            lm.put("inspectionProcessYc",tmodel.getInspectionProcessYc());
            lm.put("fishYc",tmodel.getFishYc());
            lm.put("cnvYc",tmodel.getCnvYc());
            lm.put("qfPcrYc",tmodel.getQfPcrYc());
            lm.put("karyotypingYc",tmodel.getKaryotypingYc());
            lm.put("bsignRc",tmodel.getBsignRc());
            lm.put("afTypeNameRc",tmodel.getAfTypeNameRc());
            lm.put("inspectionProcessRc",tmodel.getInspectionProcessRc());
            lm.put("fishRc",tmodel.getFishRc());
            lm.put("cnvRc",tmodel.getCnvRc());
            lm.put("qfPcrRc",tmodel.getQfPcrRc());
            lm.put("karyotypingRc",tmodel.getKaryotypingRc());
            lm.put("bsignQc",tmodel.getBsignQc());
            lm.put("afTypeNameQc",tmodel.getAfTypeNameQc());
            lm.put("inspectionProcessQc",tmodel.getInspectionProcessQc());
            lm.put("fishQc",tmodel.getFishQc());
            lm.put("cnvQc",tmodel.getCnvQc());
            lm.put("qfPcrQc",tmodel.getQfPcrQc());
            lm.put("karyotypingQc",tmodel.getKaryotypingQc());
            lm.put("strFlupTime",tmodel.getStrFlupTime());
            lm.put("gestResultName",tmodel.getGestResultName());
            lm.put("nbcSex",tmodel.getNbcSex());
            lm.put("strNbcBirthdayOrChildbirthDate",tmodel.getStrNbcBirthdayOrChildbirthDate());
            lm.put("nbcBw", tmodel.getNbcBw() == null ? "" : tmodel.getNbcBw().toString());
            lm.put("gestDays",tmodel.getGestDays());
            lm.put("birthPlace",tmodel.getBirthPlace());
            lm.put("birthInspection",tmodel.getBirthInspection());
            lm.put("flupCure",tmodel.getFlupCure());
            lm.put("inducedSpecial",tmodel.getInducedSpecial());
            lm.put("inducedCauseName",tmodel.getInducedCauseName());
            lm.put("isSpecKeep",tmodel.getIsSpecKeep());
            lm.put("specKeepName",tmodel.getSpecKeepName());
            lm.put("flupRemark",tmodel.getFlupRemark());
            lm.put("diacrisisRemark",tmodel.getDiacrisisRemark());
            lm.put("isPme",tmodel.getIsPme());
            lm.put("nbcLength",tmodel.getNbcLength() == null ? "" : tmodel.getNbcLength().toString());
            lm.put("nbcHeadCircumference",tmodel.getNbcHeadCircumference() == null ? "" : tmodel.getNbcHeadCircumference().toString());
            lm.put("oneApgar",tmodel.getOneApgar() == null ? "" : tmodel.getOneApgar().toString());
            lm.put("fiveApgar",tmodel.getFiveApgar() == null ? "" : tmodel.getFiveApgar().toString());
            listMap.add(lm);
        }
        map.put("maplist", listMap);
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        response.setContentType("application/x-download");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        workbook.write(out);
        byte[] bytes = out.toByteArray();
        return this.toResponseEntity(true, "患者综合信息 "+fileName, "application/x-download", bytes);
    }
}
